<extend name="Public/base"/>

<block name="body">
    <style>
        .tw{
            border-bottom: 2px solid #ccc;
        }
    </style>
    <div class="main-title">
        <h2>{$info['id']?'编辑':'新增'}关键字</h2>
    </div>
    <form action="{:U('Wechat/gjz_add')}" id="for" method="post" enctype="multipart/form-data" >
        <div class="form-item">
            <label class="item-label">关键字名称<span class="check-tips">（关键字名会作为默认的昵称）</span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="rule_name" value="">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">触发关键字<span class="check-tips"></span></label>
            <div class="controls">
                <input type="text" class="text input-large" name="keyword" value="">
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">类型</label>
            <div class="controls">
                <select name="type" id="type">
                    <option value="1">文本</option>
                    <option value="2">图文</option>
                </select>
            </div>
        </div>
        <div class="form-item">
            <label class="item-label">内容<span class="check-tips"></span></label>
            <div class="controls text_wb">
                <input type="text" class="text input-large" name="text" value="">
            </div>

            <div class="controls text_tw" style="display: none">
                <div class="tw">
                    图文消息标题： <input type="text" name="tw_title[]"> <br/>
                    图文消息描述： <input type="text" name="tw_description[]"> <br/>
                    点击图文消息跳转链接： <input type="text" name="tw_url[]"> <br/>
                    图片： <input type="file" name="tw_img[]"> <br/>
                </div>

                <div style="line-height: 30px;cursor: pointer;" title="添加" id="twadd" dat="1">++++++++++++++</div>
            </div>
        </div>
        <div class="form-item">
            <input type="hidden" name="id" value="{$info.id|default=''}">
            <input class="btn submit-btn" id="submit" type="submit" target-form="form-horizontal">

            <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">

        $('#type').change(function () {
            var type=$(this).val();
            if(type==1){
                $('.text_wb').show();
                $('.text_tw').hide();
            }else{
                $('.text_tw').show();
                $('.text_wb').hide();
            }
        })

        $('#twadd').click(function(){
            var dat=Number($(this).attr('dat'));
            if(dat>3){
                return false;
            }

            var html=' <div class="tw">\n' +
                '                    图文消息标题： <input type="text" name="tw_title[]"> <br/>\n' +
                '                    图文消息描述： <input type="text" name="tw_description[]"> <br/>\n' +
                '                    点击图文消息跳转链接： <input type="text" name="tw_url[]"> <br/>\n' +
                '                    图片： <input type="file" name="tw_img[]"> <br/>\n' +
                '                </div>';
            $("#twadd").before(html);

            $(this).attr('dat',dat+1);
        });

        // Think.setValue("type", {$info.type|default=0});
        // Think.setValue("group", {$info.group|default=0});
        //导航高亮
        $('.side-sub-menu').find('a[href="{:U('Wechat/index')}"]').closest('li').addClass('current');
    </script>
</block>
